#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve() {
    int n;
    cin >> n;
    int cnt[6] = {3, 1, 2, 1, 0, 1};
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) {
        int x = a[i];
        if(x <= 5) {
            cnt[x]--;
        }
        int f = 0;
        for(int j = 0; j < 6; j++) {
            if(cnt[j] > 0){
                f = 1;
                break;
            }
        }
        if(f == 0) {
            cout << i + 1 << endl;
            return;
        }
    }
    cout << 0 << endl;
}

signed main() {
    int t = 1;
    cin >> t;
    while(t--) solve();
    return 0;
}